package io.renren.modules.dangan.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.dangan.entity.DaServerEntity;
import io.renren.modules.dangan.service.DaServerService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * ${comments}
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-08-03 22:04:03
 */
@RestController
@RequestMapping("dangan/daserver")
@CrossOrigin
public class DaServerController {
    @Autowired
    private DaServerService daServerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("dangan:daserver:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = daServerService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{serverxh}")
//    @RequiresPermissions("dangan:daserver:info")
    public R info(@PathVariable("serverxh") Integer serverxh){
        DaServerEntity daServer = daServerService.getById(serverxh);

        return R.ok().put("daServer", daServer);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("dangan:daserver:save")
    public R save(@RequestBody DaServerEntity daServer){
        daServerService.save(daServer);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("dangan:daserver:update")
    public R update(@RequestBody DaServerEntity daServer){
        ValidatorUtils.validateEntity(daServer);
//        daServerService.updateById(daServer);
        daServerService.saveOrUpdate(daServer);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("dangan:daserver:delete")
    public R delete(@RequestBody Integer[] serverxhs){
        daServerService.removeByIds(Arrays.asList(serverxhs));

        return R.ok();
    }

}
